package org.chl.chapter05.controller;

import java.util.List;

import org.chl.chapter05.logic.UserLogic;
import org.chl.chapter05.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	UserLogic logic;

	@PostMapping("addUser")
	public User addUser(@RequestBody User user) {
		return logic.save(user);
	}

	@PostMapping("updateUser")
	public User updateUser(@RequestBody User user) {
		return logic.save(user);
	}

	@GetMapping("deleteUserByid")
	public String deleteUserByid(Integer id) {
		logic.deleteUserById(id);

		return "删除成功id:" + id;
	}

	@GetMapping("getUserByid")
	public User getUserByid(Integer id) {
		return logic.getUserById(id);
	}

	@GetMapping("getAllUsers")
	public List<User> getAllUsers() {
		return logic.getAllUsers();
	}
}
